import service from '@/utils/request'
import { useUserStore } from '@/pinia/modules/user'
const userStore = useUserStore()

export const getPlantList = (data) => {
    return new Promise((resolve,reject)=>{
      service.post('/boss/tanc_plant_header/tanc_plant_header-list',data)
      .then(res=>{
        resolve(res.data) 
      })
    })
}

// 作物列表
export const getCropList = (data) => {
    return new Promise((resolve,reject)=>{
      service.post('/boss/crop/tanc-crop-list',data)
      .then(res=>{
        resolve(res.data) 
      })
    })
}

// 种植阶段列表
export const getStageList = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_stage/tanc_stage-list',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// 任务列表（种植阶段下的任务列表）
export const getTaskList = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_stage_task/tanc_stage_task-list',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// 新增任务
export const addTask = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_stage_task/tanc_stage_task-add',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// 删除任务
export const delTask = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_stage_task/tanc_stage_task-delete',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// 地块分组列表
export const getLandGroupList = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/farmland-group/farmland-group-list',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// 地块列表
export const getLandList = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc-farm-land/tanc-farm-land-list',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// 新增种植计划
export const addFarmPlant = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_plant_header/tanc_plant_header-add',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// 编辑种植计划
export const editFarmPlant = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_plant_header/tanc_plant_header-edit',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// 删除种植计划
export const delFarmPlant = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_plant_header/tanc_plant_header-delete',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getPlantDetail = (plantHeaderId) => {
  return new Promise((resolve,reject)=>{
    service.get(`/boss/tanc_plant_header/tanc_plant_header-get?plantHeaderId=${plantHeaderId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getDropdownList = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/common/lov/page',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const get_plant_lineList = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_plant_line/tanc_plant_line-list',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const get_plant_batch_confirm = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_plant_line/tanc_plant_line-batch-confirm',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const get_plant_line_confirm = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_plant_line/tanc_plant_line-confirm',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getPlantLogList = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_plant_operation_logs/tanc_plant_operation_logs-list',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getPlantTaskStatistics = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_plant_line/tanc_plant_line-Stat',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getPlantLinelistDetail = (id) => {
  return new Promise((resolve,reject)=>{
    service.get(`/boss/tanc_plant_line/tanc_plant_line-get?plantLineId=${id}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const editPlantLineItem = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_plant_line/tanc_plant_line-edit',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const cancelPlantLineItem = (data) => {
  return new Promise((resolve,reject)=>{
    service.put('/boss/tanc_plant_line/tanc_plant_line-update-status',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// 农场列表,要求展示作物，就用该接口
export const getFarmList = (data) => {
  return new Promise((resolve,reject)=>{
    // roleId=1为平台管理员
    if(!data.companyId){
      const companyId = userStore.userInfo.roleId==1?null:userStore.userInfo.companyId
      data.companyId = companyId
    }
     
    service.post('/boss/farm/farm-list',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}
// 农场列表-不含作物信息（没要求展示作物，就用该接口）
export const getFarmList2 = (data) => {
  return new Promise((resolve,reject)=>{
    // roleId=1为平台管理员
    if(!data.companyId){
      const companyId = userStore.userInfo.roleId==1?null:userStore.userInfo.companyId
      data.companyId = companyId
    }
     
    service.post('/boss/farm/farm-list-nocrop',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getLandDetail = (farmLandId) => {
  return new Promise((resolve,reject)=>{
    service.get(`/boss/tanc-farm-land/tanc-farm-land-get?farmLandId=${farmLandId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getSoilNutrient = (farmLandId) => {
  return new Promise((resolve,reject)=>{
    service.get(`/boss/farmland-composition/farmland-composition-get?farmLandId=${farmLandId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const addGroup = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/farmland-group/farmland-group-add',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const delGroup = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/farmland-group/farmland-group-delete',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getGeologyList = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/farm-land-geology/farm-land-geology-list',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const addFarmLand = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc-farm-land/tanc-farm-land-add',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const editFarmLand = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc-farm-land/tanc-farm-land-edit',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}
export const delFarmLand = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc-farm-land/tanc-farm-land-delete',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const uploadComposition = (fromData) => {
  return new Promise((resolve,reject)=>{
    let config = {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    }
    service.post('/boss/farmland-composition/import-farmland-composition',fromData,config)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const delComposition = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/farmland-composition/farmland-composition-delete',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getFarmCount = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/farm/farm-count',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getFarmRecordList = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/tanc_stage_task_mine/tanc_stage_task_mine-list',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getRecordDetail = (id) => {
  return new Promise((resolve,reject)=>{
    service.get(`/boss/tanc_stage_task_mine/tanc_stage_task_mine-get2?stageTaskMineId=${id}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getBudget = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/statistical/budget-manage-count',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getAssetTrend = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/statistical/farmland-area-grew-count',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getAssetCondition= (companyId) => {
  return new Promise((resolve,reject)=>{
    service.get(`/boss/statistical/farmland-asset-status-count?companyId=${companyId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getFarmDistribution = (companyId) => {
  return new Promise((resolve,reject)=>{
    service.get(`/boss/statistical/farmland-distribution-count?companyId=${companyId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getFarmWeather = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/weather/farm-weather-leftside',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getHourWeather = (hourType,location) => {
  return new Promise((resolve,reject)=>{
    service.get(`/boss/weather/hour?hourType=${hourType}&location=${location}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getDailyWeather = (dayType,location) => {
  return new Promise((resolve,reject)=>{
    service.get(`/boss/weather/daily?dayType=${dayType}&location=${location}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getNotifyList = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/notify/boss-receipt-notify-list',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getStageTaskCount = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/statistical/stage-task-count',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getGrowthCompareCount = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/statistical/growth-compare-count',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// 获取腾讯地址
export const getTenArea = () => {
  return new Promise((resolve,reject)=>{
    service.get('/boss/notify/district')
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getUptM= (farmId) => {
  // return new Promise((resolve,reject)=>{
  //   service.get(`/boss/farmland-composition/template-file?farmId=${farmId}`)
  //   .then(res=>{
  //     resolve(res.data) 
  //   })
  // })
  return service({
    url: `/boss/farmland-composition/template-file?farmId=${farmId}`,
    method: 'get',
    responseType: 'blob'
  })
}








